package com.example.ffepeg.ffe;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Clearness {
    public static BufferedImage resizeImage(BufferedImage originalImage, int newWidth, int newHeight) throws IOException {
        // 创建一个目标图像缓冲区，设置类型为TYPE_INT_ARGB以支持透明度
        BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = resizedImage.createGraphics();

        // 设置高质量的抗锯齿渲染提示
        g.setRenderingHint(java.awt.RenderingHints.KEY_INTERPOLATION, java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setRenderingHint(java.awt.RenderingHints.KEY_RENDERING, java.awt.RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

        // 绘制调整大小后的图像
        g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
        g.dispose();

        return resizedImage;
    }

    public static void main(String[] args) {
        try {
            // 加载原始图像
            BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\Administrator\\Desktop\\hungaguo.png"));

            // 调整图像大小
            BufferedImage resizedImage = resizeImage(originalImage, 800, 600);

            // 保存调整大小后的图像
            ImageIO.write(resizedImage, "png", new File("src/main/resources/out/resized-image.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

